home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / dayofwee.sty < prev    next >
Text File  |  1995-11-25  |  6KB  |  152 lines

  1. %\DayOfWeekexpands to the day of the week ("Sunday", etc.)
  2. %\PhaseOfMoonexpands to the phase of the moon
  3. %
  4. %Written by Martin Minow of DEC (minow%bolt.dec@decwrl.dec.com).
  5. %
  6.   \newcount\dow % Gets day of the week
  7.   \newcount\leap % Leap year fingaler
  8.   \newcount\x % Temp register
  9.   \newcount\y % Another temp register
  10. \def\DayOfWeek\%
  11. %
  12. % Calculate day of the week, return "Sunday", etc.
  13. %
  14. % \newcount\dow % Gets day of the week
  15. % \newcount\leap % Leap year fingaler
  16. % \newcount\x % Temp register
  17. % \newcount\y % Another temp register
  18. %leap = year + (month - 14)/12;
  19.   \leap=\month \advance\leap by -14 \divide\leap by 12
  20.   \advance\leap by \year
  21. %dow = (13 * (month + 10 - (month + 10)/13*12) - 1)/5
  22.   \dow=\month \advance\dow by 10
  23.   \y=\dow \divide\y by 13 \multiply\y by 12
  24.   \advance\dow by -\y \multiply\dow by 13 \advance\dow by -1 \divide\dow by 5
  25. %dow += day + 77 + 5 * (leap % 100)/4
  26.   \advance\dow by \day \advance\dow by 77
  27.   \x=\leap \y=\x \divide\y by 100 \multiply\y by 100 \advance\x by -\y
  28.   \multiply\x by 5 \divide\x by 4 \advance\dow by \x
  29. %dow += leap / 400
  30.   \x=\leap \divide\x by 400 \advance\dow by \x
  31. %dow -= leap / 100 * 2;
  32. %dow = (dow % 7)
  33.   \x=\leap \divide\x by 100 \multiply\x by 2 \advance\dow by -\x
  34.   \x=\dow \divide\x by 7 \multiply\x by 7 \advance\dow by -\x
  35.   \ifcase\dow Sunday\or Monday\or Tuesday\or Wednesday\or
  36. Thursday\or Friday\or Saturday\fi
  37. \
  38. %%
  39. %%
  40. %%
  41.   \newcount\cent% Century number (1979 == 20)
  42.   \newcount\epact% Age of the moon on Jan. 1
  43.   \newcount\diy% Day in the year
  44.   \newcount\golden% Moon's golden number
  45.   \newcount\x% Temp
  46.   \newcount\m% Temp for modulus
  47. \def\PhaseOfMoon\%Calculate the phase of the (civil) moon.
  48. %
  49. % The routine calculates the year's epact (the age of the moon on Jan 1.),
  50. % adds this to the number of days in the year, and calculates the phase
  51. % of the moon for this date.  It returns the phase as a string, e.g.,
  52. % "new", "full", etc.
  53. %
  54. % In the algorithm:
  55. %
  56. %diyIs the day of the year - 1 (i.e., Jan 1 is day 0).
  57. %
  58. %goldenIs the number of the year in the Mentonic cycle, used to
  59. %determine the position of the calender moon.
  60. %
  61. %epactIs the age of the calender moon (in days) at the beginning
  62. %of the year.    To calculate epact, two century-based
  63. %corrections are applied:
  64. %Gregorian:(3 * cent)/4 - 12
  65. %is the number of years such as 1700, 1800 when
  66. %leap year was not held.
  67. %Clavian:(((8 * cent) + 5) / 25) - 5
  68. %is a correction to the Mentonic cycle of about
  69. %8 days every 2500 years.     Note that this will
  70. %overflow 16 bits in the year 409600.     Beware.
  71. %
  72. % The algorithm is accurate for the Gregorian calender only.
  73. %
  74. % The magic numbers used in the phase calculation are as follows:
  75. % 29.5The moon's period in days.
  76. %17729.5 scaled by 6
  77. % 22(29.5 / 8) scaled by 6 (this gets the phase)
  78. % 11((29.5 / 8) / 2) scaled by 6
  79. %
  80. % Theoretically, this should yield a number in the range 0 .. 7.  However,
  81. % two days per year, things don't work out too well.
  82. %
  83. % Epact is calculated by the algorithm given in Knuth vol. 1 (calculation
  84. % of Easter).  See also the article on Calenders in the Encyclopaedia
  85. % Britannica and Knuth's algorithm in CACM April 1962, page 209.
  86. %
  87.   \diy=\day \advance\diy by \ifcase\month% Jan 1 == 0
  88. -1\or -1\or 30\or 58\or 89\or 119\or 150\or% Jan .. Jun
  89. 180\or 211\or 241\or 272\or 303\or 333\fi% Jul .. Dec
  90. %if ((month > 2) && ((year % 4 == 0) &&
  91. %      ((year % 400 == 0) \\ (year % 100 != 0))))
  92. %diy++;/* Leapyear fixup*/
  93.   \ifnum \month>2
  94.     \x=\year \m=\x \divide\m by 4 \multiply\m by 4 \advance\x by -\m
  95.     \ifnum \x=0% month > 2 and maybe leapyear
  96.       \x=\year \m=\x \divide\m by 400 \multiply\m by 400 \advance\x by -\m
  97.       \ifnum \x=0% 2000 is a leap year
  98. \advance\diy by 1% so it's one day later
  99.       \else% not 2000, check other '00's
  100. \x=\year \m=\x \divide\m by 100 \multiply\m by 100 \advance\x by -\m
  101. \ifnum \x>0% not some other '00' year
  102.      \advance\diy by 1% it's still one day later
  103. \fi% not odd century
  104.       \fi% not 2000-type century
  105.     \fi% not leapish year
  106.   \fi% not march or later
  107. %cent = (year / 100) + 1;/* Century number*/
  108. %golden = (year % 19) + 1;/* Golden number*/
  109.   \cent=\year \divide\cent by 100 \advance\cent by 1
  110.   \golden=\year
  111.   \m=\year \divide\m by 19 \multiply\m by 19 \advance\golden by -\m
  112.   \advance\golden by 1
  113. %epact = ((11 * golden) + 20/* Golden number*/
  114. %+ (((8 * cent) + 5) / 25) - 5/* 400 year cycle*/
  115. %- (((3 * cent) / 4) - 12)) % 30;/* Leap year correction*/
  116.   \epact=11 \multiply\epact by \golden
  117.   \advance\epact by 20
  118.   \x=8 \multiply\x by \cent \advance\x by 5
  119.   \divide\x by 25 \advance\x by -5
  120.   \advance\epact by \x
  121.   \x=3 \multiply\x by \cent \divide\x by 4 \advance\x by -12
  122.   \advance\epact by -\x
  123.   \m=\epact \divide\m by 30 \multiply\m by 30 \advance\epact by -\m
  124. %if (epact <= 0)
  125. %epact += 30;/* Age range is 1 .. 30*/
  126. %if ((epact == 25 && golden > 11) \\ epact == 24)
  127. %epact++;
  128.   \ifnum \epact<0
  129.     \advance\epact by 30
  130.   \fi
  131.   \ifnum \epact=25
  132.     \ifnum \golden>11
  133.       \advance \epact by 1
  134.     \fi
  135.   \else
  136.     \ifnum \epact=24
  137.       \advance \epact by 1
  138.     \fi
  139.   \fi
  140. %
  141. % Calculate the phase, using the magic numbers defined above.
  142. % Note that phase may be equal to 8 (== 0) on two days of the year
  143. % due to the way the algorithm was implemented.
  144. %phase = (((((diy + epact) * 6) + 11) % 177) / 22) & 7;
  145. %
  146.   \x=\diy \advance\x by \epact \multiply\x by 6 \advance\x by 11
  147.   \m=\x \divide\m by 177 \multiply\m by 177 \advance\x by -\m
  148.   \divide\x by 22
  149.   \ifcase\x new\or waxing crescent\or in its first quarter\or
  150. waxing gibbous\or full\or waning gibbous\or
  151. in its last quarter\or waning crescent\or new\fi
  152.